<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/12
 * Time: 17:16
 */

namespace Modules\Api\Http\Controllers;

use HiCommon\Service\WxLoginService;
use Illuminate\Support\Facades\Request;

class ThirdPartyController extends BaseController
{

    /*微信登录*/
    public function wx_login(){

        try {
            $s_code = str_trim(Request::input('code',''));
            $result = WxLoginService::api_wechat_login($s_code);
            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*微信登录绑定手机号*/
    public function wx_bind_phone(){
        try {
//            $n_id = intval(Request::input('id',0));
//            $s_phone = str_trim(Request::input('phone',''));
//            $s_code = str_trim(Request::input('code',''));

            $arr_input = Request::input();
            shiwu_start();
            $result = WxLoginService::api_wechat_bind_phone($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*绑定微信app*/
    public function bind_wechat(){
        try {
            $n_uid = intval(api_user_id());
            $s_code = str_trim(Request::input('code',''));//微信code
            $result = WxLoginService::api_bind_wechat_app($n_uid,$s_code);
            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*解绑微信*/
    public function unbind_wechat(){
        try {
            $n_uid = intval(api_user_id());
            $result = WxLoginService::api_unbind_wechat_app($n_uid);
            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }



}